#read uflp problem as MIP
import sys

def get_words(line):
    """Return a list of the tokens in line."""
    line = line.replace("\t", " ")
    line = line.replace("\v", " ")
    line = line.replace("\r", " ")
    line = line.replace("\n", " ")
    while line.count("  "):
        line = line.replace("  ", " ")
    line = line.strip()
    return [word + " " for word in line.split(" ")]

def read_dat_file(filename):
    f = open(filename)
    allwords = []
    for line in f:
        allwords += get_words(line)
    return allwords

#read_dat_file("a05100")

def read_uflp(filename):

    f = open(filename)
    filename = f.readline()
    header = get_words( f.readline() )
    
    num_fac = int(header[0]) # number of facilities 
    num_cty = int(header[1]) # number of cities(client)
    
    fx_cost = [0.0] * num_fac
    cn_cost = []
    cty_cn_cost = [0.0] * num_fac
    
    for i in range(num_cty):

        words = get_words( f.readline() )

        fx_cost[i] = float( words[1] )

        for j in range(num_fac):
            cty_cn_cost[j] = float( words[j+2] )

        cn_cost.append( list(cty_cn_cost) )

    return num_fac, num_cty, fx_cost, cn_cost 
        
"""
num_fac, num_cty, fx_cost, cn_cost = read_uflp(sys.argv[1])
print num_fac
print num_cty
print fx_cost
"""

#print cn_cost
